/* ==================== 移动端优化样式 ==================== */

/* 防止横向滚动 - 全局设置 */
html, body {
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* ==================== 小屏幕设备 (≤480px) ==================== */
@media (max-width: 480px) {
    body {
        padding: 8px;
        font-size: 14px;
    }
    
    .container {
        width: 100%;
        border-radius: 8px;
        overflow-x: hidden;
        margin: 0;
    }
    
    header {
        padding: 15px 10px;
    }
    
    h1 {
        font-size: 20px;
        margin-bottom: 8px;
    }
    
    .subtitle {
        font-size: 14px;
    }
    
    .main-content {
        flex-direction: column;
        padding: 15px 10px;
        gap: 15px;
    }
    
    .input-section, 
    .result-section {
        width: 100%;
        min-width: 100%;
        padding: 15px;
        margin-right: 0;
        margin-bottom: 0;
        box-sizing: border-box;
    }
    
    .input-section-header {
        padding: 8px;
        margin-bottom: 12px;
    }
    
    .input-section-header h2 {
        font-size: 18px;
    }
    
    .form-group {
        margin-bottom: 12px;
    }
    
    .radio-group {
        flex-direction: column;
        gap: 8px;
    }
    
    .datetime-inputs {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .bazi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        margin-bottom: 15px;
    }
    
    .bazi-column {
        padding: 10px 5px;
    }
    
    .bazi-content {
        font-size: 16px;
    }
    
    .bazi-detail {
        font-size: 12px;
    }
    
    .result-header {
        padding: 8px;
        font-size: 14px;
    }
    
    .list-item {
        flex-direction: column;
        align-items: flex-start;
        padding: 6px 0;
    }
    
    .result-text {
        padding: 10px;
        font-size: 13px;
        overflow-x: auto;
        white-space: pre-wrap;
        word-break: break-word;
        -webkit-overflow-scrolling: touch;
    }
    
    .additional-info {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    button {
        padding: 14px;
        font-size: 16px;
        min-height: 44px; /* 触摸友好的最小高度 */
    }
    
    footer {
        padding: 10px 5px;
        font-size: 11px;
    }
    
    /* 确保所有元素不会溢出容器 */
    * {
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Markdown 表格在小屏幕上优化 */
    .markdown-body .table-container {
        width: 100%;
        overflow-x: auto;
        overflow-y: visible;
        margin: 15px 0;
        padding: 0;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: #d4b16a #f9f3e9;
        position: relative;
        /* 添加渐变提示，表明可以滚动 */
        background: linear-gradient(to right, transparent 0%, transparent 95%, rgba(212, 177, 106, 0.1) 100%);
    }
    
    .markdown-body .table-container::after {
        content: '→';
        position: absolute;
        right: 8px;
        top: 8px;
        font-size: 12px;
        color: #d4b16a;
        opacity: 0.5;
        pointer-events: none;
        font-weight: bold;
    }
    
    .markdown-body .table-container::-webkit-scrollbar {
        height: 10px;
    }
    
    .markdown-body .table-container::-webkit-scrollbar-track {
        background: #f9f3e9;
        border-radius: 5px;
    }
    
    .markdown-body .table-container::-webkit-scrollbar-thumb {
        background: #d4b16a;
        border-radius: 5px;
        border: 2px solid #f9f3e9;
    }
    
    .markdown-body .table-container::-webkit-scrollbar-thumb:hover {
        background: #8b0000;
    }
    
    .markdown-body table {
        font-size: 13px;
        min-width: 100%;
        width: max-content;
        border-collapse: collapse;
        margin: 0;
        background: #fff;
        table-layout: auto;
        display: table;
    }
    
    .markdown-body table th {
        padding: 10px 8px;
        font-size: 12px;
        white-space: nowrap;
        min-width: 60px;
        position: sticky;
        left: 0;
        z-index: 1;
    }
    
    .markdown-body table th:first-child {
        position: sticky;
        left: 0;
        z-index: 2;
    }
    
    .markdown-body table td {
        padding: 10px 8px;
        font-size: 12px;
        word-break: break-word;
        -webkit-hyphens: auto;
        hyphens: auto;
        line-height: 1.5;
        min-width: 60px;
        max-width: 200px;
    }
    
    /* 第一列可以固定，方便查看 */
    .markdown-body table td:first-child {
        position: sticky;
        left: 0;
        background: #fffaf0;
        z-index: 1;
        font-weight: 500;
        border-right: 2px solid #d4b16a;
    }
    
    .markdown-body table tr:nth-child(even) td:first-child {
        background: #f9f3e9;
    }
    
    .markdown-body h1 {
        font-size: 22px;
    }
    
    .markdown-body h2 {
        font-size: 18px;
    }
    
    .markdown-body h3 {
        font-size: 16px;
    }
}

/* ==================== 超小屏幕设备 (≤320px) ==================== */
@media (max-width: 320px) {
    body {
        padding: 5px;
        font-size: 13px;
    }
    
    .container {
        border-radius: 6px;
    }
    
    header {
        padding: 12px 8px;
    }
    
    h1 {
        font-size: 18px;
    }
    
    .subtitle {
        font-size: 12px;
    }
    
    .main-content {
        padding: 10px 8px;
        gap: 12px;
    }
    
    .input-section, 
    .result-section {
        padding: 12px 10px;
    }
    
    .input-section-header h2 {
        font-size: 16px;
    }
    
    .bazi-grid {
        grid-template-columns: 1fr;
        gap: 6px;
    }
    
    .bazi-column {
        padding: 8px 4px;
    }
    
    .bazi-content {
        font-size: 15px;
    }
    
    h2 {
        font-size: 18px;
    }
    
    .result-text {
        padding: 8px;
        font-size: 12px;
    }
    
    button {
        padding: 12px;
        font-size: 15px;
    }

    footer {
        padding: 8px 4px;
        font-size: 10px;
    }
    
    footer p {
        max-width: 95%;
        line-height: 1.7;
    }
    
    /* 超小屏幕表格优化 */
    .markdown-body .table-container {
        margin: 10px 0;
    }
    
    .markdown-body .table-container::after {
        font-size: 10px;
        right: 5px;
        top: 6px;
    }
    
    .markdown-body table {
        font-size: 11px;
    }
    
    .markdown-body table th {
        padding: 8px 5px;
        font-size: 10px;
        min-width: 50px;
    }
    
    .markdown-body table td {
        padding: 8px 5px;
        font-size: 10px;
        min-width: 50px;
        max-width: 150px;
    }
    
    .markdown-body h1 {
        font-size: 20px;
    }
    
    .markdown-body h2 {
        font-size: 16px;
    }
    
    .markdown-body h3 {
        font-size: 14px;
    }
}

/* ==================== 中等屏幕设备 (481px - 768px) ==================== */
@media (min-width: 481px) and (max-width: 768px) {
    .container {
        max-width: 100%;
    }
    
    .bazi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .main-content {
        padding: 18px;
    }
    
    /* 中等屏幕表格优化 */
    .markdown-body .table-container {
        margin: 18px 0;
    }
    
    .markdown-body table {
        font-size: 14px;
    }
    
    .markdown-body table th {
        padding: 12px 10px;
        font-size: 13px;
    }
    
    .markdown-body table td {
        padding: 12px 10px;
        font-size: 13px;
        max-width: 250px;
    }
}

/* ==================== 触摸设备优化 ==================== */
@media (hover: none) and (pointer: coarse) {
    /* 提高触摸目标的可访问性 */
    input, 
    select, 
    button {
        min-height: 44px;
        -webkit-tap-highlight-color: rgba(139, 0, 0, 0.1);
    }
    
    .radio-option label {
        padding: 10px 0;
        min-height: 44px;
        display: flex;
        align-items: center;
        -webkit-tap-highlight-color: rgba(139, 0, 0, 0.1);
    }
    
    .radio-option input {
        width: 20px;
        height: 20px;
        min-width: 20px;
        min-height: 20px;
    }
    
    .input-section-header {
        -webkit-tap-highlight-color: rgba(139, 0, 0, 0.1);
    }
    
    /* 改善滚动体验 */
    .result-section,
    .result-text {
        -webkit-overflow-scrolling: touch;
    }
    
    /* 触摸设备表格优化 */
    .markdown-body .table-container {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    .markdown-body table th,
    .markdown-body table td {
        touch-action: manipulation;
    }
}

/* ==================== 横屏模式优化 ==================== */
@media (max-width: 768px) and (orientation: landscape) {
    body {
        padding: 10px;
    }
    
    .main-content {
        padding: 15px;
    }
    
    .bazi-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }
    
    .input-section.collapsed {
        max-height: 60px;
    }
    
    /* 横屏模式表格优化 */
    .markdown-body .table-container {
        max-height: 70vh;
        overflow-y: auto;
    }
    
    .markdown-body table {
        font-size: 12px;
    }
    
    .markdown-body table th,
    .markdown-body table td {
        padding: 8px 6px;
    }
}

/* ==================== 高DPI屏幕优化 ==================== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .bazi-content {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}
